<template>
  <div class="home-container">
    <el-scrollbar style="height: 100%;">
      <!-- 欢迎区域 -->
      <div class="welcome-section">
        <div class="welcome-content">
          <h1>{{ greeting }}，{{ userName }}</h1>
          <p class="subtitle">{{ getWelcomeText }}</p>
          <div class="time-display">
            <i class="el-icon-time"></i>
            <span>{{ currentTime }}</span>
          </div>
        </div>
      </div>

      <!-- 快捷功能区域 -->
      <div class="quick-access">
        <!-- 管理员的快捷功能 -->
        <template v-if="$store.state.user.user && $store.state.user.user.role === 0">
          <div class="section-title">
            <h2>系统管理</h2>
            <p>快速访问系统管理功能</p>
          </div>
          <!-- 第一行 -->
          <el-row :gutter="20">
            <el-col :span="8">
              <div class="feature-card" @click="handleQuickAccess('/Home/userList')">
                <div class="card-icon">
                  <i class="el-icon-user"></i>
                </div>
                <div class="card-content">
                  <h3>用户管理</h3>
                  <p>管理系统用户账号及权限</p>
                  <el-button type="text" size="small">
                    查看详情 <i class="el-icon-arrow-right"></i>
                  </el-button>
                </div>
              </div>
            </el-col>
            <el-col :span="8">
              <div class="feature-card" @click="handleQuickAccess('/Home/admin/jobs')">
                <div class="card-icon">
                  <i class="el-icon-suitcase"></i>
                </div>
                <div class="card-content">
                  <h3>职位管理</h3>
                  <p>查看和管理所有职位信息</p>
                  <el-button type="text" size="small">
                    查看详情 <i class="el-icon-arrow-right"></i>
                  </el-button>
                </div>
              </div>
            </el-col>
            <el-col :span="8">
              <div class="feature-card" @click="handleQuickAccess('/Home/admin/applications')">
                <div class="card-icon">
                  <i class="el-icon-document"></i>
                </div>
                <div class="card-content">
                  <h3>申请管理</h3>
                  <p>查看所有职位申请记录</p>
                  <el-button type="text" size="small">
                    查看详情 <i class="el-icon-arrow-right"></i>
                  </el-button>
                </div>
              </div>
            </el-col>
          </el-row>
          <!-- 第二行 -->
          <el-row :gutter="20" style="margin-top: 20px;">
            <el-col :span="8">
              <div class="feature-card" @click="handleQuickAccess('/Home/admin/categories')">
                <div class="card-icon">
                  <i class="el-icon-collection-tag"></i>
                </div>
                <div class="card-content">
                  <h3>职位类别</h3>
                  <p>管理职位分类信息</p>
                  <el-button type="text" size="small">
                    查看详情 <i class="el-icon-arrow-right"></i>
                  </el-button>
                </div>
              </div>
            </el-col>
            <el-col :span="8">
              <div class="feature-card" @click="handleQuickAccess('/Home/admin/fees')">
                <div class="card-icon">
                  <i class="el-icon-money"></i>
                </div>
                <div class="card-content">
                  <h3>费用管理</h3>
                  <p>管理系统费用收支</p>
                  <el-button type="text" size="small">
                    查看详情 <i class="el-icon-arrow-right"></i>
                  </el-button>
                </div>
              </div>
            </el-col>
            <el-col :span="8">
              <div class="feature-card" @click="handleQuickAccess('/Home/admin/employment')">
                <div class="card-icon">
                  <i class="el-icon-user"></i>
                </div>
                <div class="card-content">
                  <h3>就业人员</h3>
                  <p>查看求职者就业情况</p>
                  <el-button type="text" size="small">
                    查看详情 <i class="el-icon-arrow-right"></i>
                  </el-button>
                </div>
              </div>
            </el-col>
          </el-row>
        </template>

        <!-- 用人单位的功能模块 -->
        <template v-if="$store.state.user.user && $store.state.user.user.role === 1">
          <div class="section-title">
            <h2>企业服务</h2>
            <p>便捷管理企业招聘相关事务</p>
          </div>
          <el-row :gutter="20">
            <el-col :span="8">
              <div class="feature-card" @click="handleQuickAccess('/Home/employer/profile')">
                <div class="card-icon">
                  <i class="el-icon-office-building"></i>
                </div>
                <div class="card-content">
                  <h3>企业信息</h3>
                  <p>管理企业基本信息与档案</p>
                  <el-button type="text" size="small">
                    查看详情 <i class="el-icon-arrow-right"></i>
                  </el-button>
                </div>
              </div>
            </el-col>
            <el-col :span="8">
              <div class="feature-card" @click="handleQuickAccess('/Home/employer/job')">
                <div class="card-icon">
                  <i class="el-icon-suitcase"></i>
                </div>
                <div class="card-content">
                  <h3>职位管理</h3>
                  <p>发布和管理招聘职位</p>
                  <el-button type="text" size="small">
                    查看详情 <i class="el-icon-arrow-right"></i>
                  </el-button>
                </div>
              </div>
            </el-col>
            <el-col :span="8">
              <div class="feature-card" @click="handleQuickAccess('/Home/employer/applications')">
                <div class="card-icon">
                  <i class="el-icon-document"></i>
                </div>
                <div class="card-content">
                  <h3>申请管理</h3>
                  <p>处理求职者投递的申请</p>
                  <el-button type="text" size="small">
                    查看详情 <i class="el-icon-arrow-right"></i>
                  </el-button>
                </div>
              </div>
            </el-col>
          </el-row>
        </template>

        <!-- 求职者的功能模块 -->
        <template v-if="$store.state.user.user && $store.state.user.user.role === 2">
          <div class="section-title">
            <h2>求职服务</h2>
            <p>便捷管理您的求职相关事务</p>
          </div>
          <el-row :gutter="20">
            <el-col :span="8">
              <div class="feature-card" @click="handleQuickAccess('/Home/seeker/profile')">
                <div class="card-icon">
                  <i class="el-icon-user"></i>
                </div>
                <div class="card-content">
                  <h3>个人信息</h3>
                  <p>管理个人基本信息与简历</p>
                  <el-button type="text" size="small">
                    查看详情 <i class="el-icon-arrow-right"></i>
                  </el-button>
                </div>
              </div>
            </el-col>
            <el-col :span="8">
              <div class="feature-card" @click="handleQuickAccess('/Home/seeker/jobs')">
                <div class="card-icon">
                  <i class="el-icon-search"></i>
                </div>
                <div class="card-content">
                  <h3>职位搜索</h3>
                  <p>浏览和搜索招聘职位</p>
                  <el-button type="text" size="small">
                    查看详情 <i class="el-icon-arrow-right"></i>
                  </el-button>
                </div>
              </div>
            </el-col>
            <el-col :span="8">
              <div class="feature-card" @click="handleQuickAccess('/Home/seeker/applications')">
                <div class="card-icon">
                  <i class="el-icon-document-checked"></i>
                </div>
                <div class="card-content">
                  <h3>我的申请</h3>
                  <p>查看职位申请进度</p>
                  <el-button type="text" size="small">
                    查看详情 <i class="el-icon-arrow-right"></i>
                  </el-button>
                </div>
              </div>
            </el-col>
          </el-row>
        </template>
      </div>
    </el-scrollbar>
  </div>
</template>

<script>
import { mapState } from 'vuex'

export default {
  name: 'HomePage',
  data() {
    return {
      currentTime: '',
      greeting: ''
    }
  },
  computed: {
    ...mapState('user', ['userName']),
    getWelcomeText() {
      const role = this.$store.state.user.user?.role
      switch(role) {
        case 0:
          return '欢迎使用再就业服务中心管理系统'
        case 1:
          return '欢迎使用再就业服务中心企业端'
        case 2:
          return '欢迎使用再就业服务中心求职端'
        default:
          return '欢迎使用再就业服务中心'
      }
    }
  },
  created() {
    this.updateTime()
    this.updateGreeting()
    // 每分钟更新一次时间
    setInterval(this.updateTime, 10000)
  },
  methods: {
    updateTime() {
      const now = new Date()
      this.currentTime = now.toLocaleTimeString('zh-CN', {
        hour12: false,
        hour: '2-digit',
        minute: '2-digit'
      })
    },
    updateGreeting() {
      const hour = new Date().getHours()
      if (hour < 6) {
        this.greeting = '夜深了'
      } else if (hour < 9) {
        this.greeting = '早安'
      } else if (hour < 12) {
        this.greeting = '上午好'
      } else if (hour < 14) {
        this.greeting = '中午好'
      } else if (hour < 17) {
        this.greeting = '下午好'
      } else if (hour < 19) {
        this.greeting = '傍晚好'
      } else {
        this.greeting = '晚上好'
      }
    },
    handleQuickAccess(route) {
      this.$router.push(route)
    }
  }
}
</script>

<style scoped>
.home-container {
  height: calc(100vh - 60px);
  background-color: #f6f8fa;
  overflow: hidden;
}

.welcome-section {
  background: linear-gradient(135deg, #3a7bd5, #00d2ff);
  border-radius: 16px;
  padding: 40px;
  margin: 30px 30px 40px;
  color: white;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
}

.quick-access {
  padding: 0 30px 30px;
}

/* 其他样式保持不变 */
.welcome-content h1 {
  font-size: 36px;
  margin: 0;
  font-weight: 600;
  letter-spacing: 1px;
}

.subtitle {
  font-size: 18px;
  opacity: 0.9;
  margin: 10px 0;
  font-weight: 300;
}

.time-display {
  margin-top: 20px;
  font-size: 20px;
  display: flex;
  align-items: center;
  opacity: 0.9;
}

.time-display i {
  margin-right: 10px;
}

.section-title {
  margin-bottom: 30px;
}

.section-title h2 {
  font-size: 24px;
  color: #2c3e50;
  margin: 0;
  font-weight: 600;
}

.section-title p {
  color: #666;
  margin: 8px 0 0;
  font-size: 16px;
}

.feature-card {
  background: white;
  border-radius: 16px;
  padding: 30px;
  height: 100%;
  transition: all 0.3s ease;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.feature-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

.feature-card:hover .card-icon {
  transform: scale(1.1);
}

.card-icon {
  font-size: 36px;
  color: #3a7bd5;
  margin-bottom: 20px;
  transition: all 0.3s ease;
  background: rgba(58, 123, 213, 0.1);
  width: 70px;
  height: 70px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-content h3 {
  font-size: 20px;
  color: #2c3e50;
  margin: 0 0 10px;
  font-weight: 600;
}

.card-content p {
  color: #666;
  margin: 0 0 15px;
  font-size: 14px;
  line-height: 1.5;
}

.el-button--text {
  color: #3a7bd5;
  font-weight: 500;
  padding: 0;
}

.el-button--text:hover {
  color: #00d2ff;
}

.el-button--text i {
  margin-left: 5px;
}

/* 响应式调整 */
@media screen and (max-width: 1200px) {
  .el-col {
    margin-bottom: 20px;
  }
}

@media screen and (max-width: 768px) {
  .welcome-section {
    padding: 30px;
    margin: 20px 20px 30px;
  }

  .welcome-content h1 {
    font-size: 28px;
  }

  .feature-card {
    padding: 20px;
  }

  .quick-access {
    padding: 0 20px 20px;
  }
}
</style>